-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[clang-driver] don't always set defaultlib=libcmt and defaultlib=oldnames #149400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Chotepud Teo (AlexRouSg) Changeswhen /MD or -fms-runtime-lib=dll or the debug equivalent is set this results in conflicting runtimes fixes #129881 Full diff: https://github.com/llvm/llvm-project/pull/149400.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index 7d31eea603087..36edeb7163e8c 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -85,8 +85,12 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(Args.MakeArgString("--dependent-lib=amath"));
}
- if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
- !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
+ StringRef msrtlib = Args.getLastArgValue(options::OPT_fms_runtime_lib_EQ, "");
+ bool dllmsrt = msrtlib.equals_insensitive("dll") ||
+ msrtlib.equals_insensitive("dll_dbg");
+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+ options::OPT__SLASH_MD, options::OPT__SLASH_MDd) &&
+ !dllmsrt && !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
CmdArgs.push_back("-defaultlib:libcmt");
CmdArgs.push_back("-defaultlib:oldnames");
}
diff --git a/clang/test/Driver/cl-runtime-flags.c b/clang/test/Driver/cl-runtime-flags.c
index 2a6151e08c046..7fe4f543ac806 100644
--- a/clang/test/Driver/cl-runtime-flags.c
+++ b/clang/test/Driver/cl-runtime-flags.c
@@ -38,6 +38,8 @@
// CHECK-MD: "-D_DLL"
// CHECK-MD: "--dependent-lib=msvcrt"
// CHECK-MD: "--dependent-lib=oldnames"
+// CHECK-MD-NOT: "-defaultlib:libcmt"
+// CHECK-MD-NOT: "-defaultlib:oldnames"
// RUN: %clang_cl -### /MDd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MDd %s
// RUN: %clang -### --target=x86_64-windows-msvc -fms-runtime-lib=dll_dbg -- \
@@ -47,6 +49,8 @@
// CHECK-MDd: "-D_DLL"
// CHECK-MDd: "--dependent-lib=msvcrtd"
// CHECK-MDd: "--dependent-lib=oldnames"
+// CHECK-MDd-NOT: "-defaultlib:libcmt"
+// CHECK-MDd-NOT: "-defaultlib:oldnames"
// RUN: %clang_cl -### /LD -- %s 2>&1 | FileCheck -check-prefix=CHECK-LD %s
// RUN: %clang_cl -### /LD /MT -- %s 2>&1 | FileCheck -check-prefix=CHECK-LD %s
|
@llvm/pr-subscribers-clang-driver Author: Chotepud Teo (AlexRouSg) Changeswhen /MD or -fms-runtime-lib=dll or the debug equivalent is set this results in conflicting runtimes fixes #129881 Full diff: https://github.com/llvm/llvm-project/pull/149400.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index 7d31eea603087..36edeb7163e8c 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -85,8 +85,12 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(Args.MakeArgString("--dependent-lib=amath"));
}
- if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
- !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
+ StringRef msrtlib = Args.getLastArgValue(options::OPT_fms_runtime_lib_EQ, "");
+ bool dllmsrt = msrtlib.equals_insensitive("dll") ||
+ msrtlib.equals_insensitive("dll_dbg");
+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+ options::OPT__SLASH_MD, options::OPT__SLASH_MDd) &&
+ !dllmsrt && !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
CmdArgs.push_back("-defaultlib:libcmt");
CmdArgs.push_back("-defaultlib:oldnames");
}
diff --git a/clang/test/Driver/cl-runtime-flags.c b/clang/test/Driver/cl-runtime-flags.c
index 2a6151e08c046..7fe4f543ac806 100644
--- a/clang/test/Driver/cl-runtime-flags.c
+++ b/clang/test/Driver/cl-runtime-flags.c
@@ -38,6 +38,8 @@
// CHECK-MD: "-D_DLL"
// CHECK-MD: "--dependent-lib=msvcrt"
// CHECK-MD: "--dependent-lib=oldnames"
+// CHECK-MD-NOT: "-defaultlib:libcmt"
+// CHECK-MD-NOT: "-defaultlib:oldnames"
// RUN: %clang_cl -### /MDd -- %s 2>&1 | FileCheck -check-prefix=CHECK-MDd %s
// RUN: %clang -### --target=x86_64-windows-msvc -fms-runtime-lib=dll_dbg -- \
@@ -47,6 +49,8 @@
// CHECK-MDd: "-D_DLL"
// CHECK-MDd: "--dependent-lib=msvcrtd"
// CHECK-MDd: "--dependent-lib=oldnames"
+// CHECK-MDd-NOT: "-defaultlib:libcmt"
+// CHECK-MDd-NOT: "-defaultlib:oldnames"
// RUN: %clang_cl -### /LD -- %s 2>&1 | FileCheck -check-prefix=CHECK-LD %s
// RUN: %clang_cl -### /LD /MT -- %s 2>&1 | FileCheck -check-prefix=CHECK-LD %s
|
…ames when /MD or -fms-runtime-lib=dll or the debug equivalent is set this results in conflicting runtimes fixes llvm#129881
What is the purpose of explicitly adding 'defaultlib' here? When compiling with MSVC header files, the generated object files should already contain the appropriate directives indicating the defaultlib. |
when /MD or -fms-runtime-lib=dll or the debug equivalent is set this results in conflicting runtimes
fixes #129881